package com.example.beiwang.db.record;

import android.database.Cursor;
import android.database.CursorWrapper;

import com.example.beiwang.model.Record;

import java.util.Date;

/**
 * 辅助查询语句的工具类
 * */
public class RecordCursorWrapper extends CursorWrapper {
    /**
     * Creates a cursor wrapper.
     *
     * @param cursor The underlying cursor to wrap.
     */
    public RecordCursorWrapper(Cursor cursor) {
        super(cursor);
    }


    public Record getRecord(){
        int id = getInt(getColumnIndex(RecordSchema.Cols.ID));
        String title = getString(getColumnIndex(RecordSchema.Cols.TITLE));
        String content = getString(getColumnIndex(RecordSchema.Cols.CONTENT));
        String textThinking = getString(getColumnIndex(RecordSchema.Cols.TEXT_THINKING));
        String pic = getString(getColumnIndex(RecordSchema.Cols.PICTURE));
        int completed = getInt(getColumnIndex(RecordSchema.Cols.COMPLETED));
        long finishDate = getLong(getColumnIndex(RecordSchema.Cols.FINISH_DATE));
        Record record = new Record();
        record.setId(id);
        record.setTitle(title);
        record.setContent(content);
        record.setTextThinking(textThinking);
        record.setPicture(pic);
        record.setCompleted(completed!=0);
        record.setFinishDate(new Date(finishDate));
        return record;
    }
}